<?php
namespace Rainrock\Framework\kernel\base;


/**
*	文件夹
*/
final class File{
	
	/**
	*	获取路径下的文件夹
	*/
	public static function getFolder($path, $call=null, $cans=array())
	{
		$rows = array();
		$limit= (int)Rock::arrvalue($cans, 'limit', '0'); $count = 0;
		if(is_dir($path)){
			$files 		= scandir($path, SCANDIR_SORT_DESCENDING);
			foreach ($files as $file) {
				if ($file != "." && $file != ".."){
					$count ++;
					if($call != null)$file = $call($file, $path);
					$rows[] = $file;
					if($limit > 0 && $limit == $count)break;
				}
			}
		}
		return $rows;
	}
	
	/**
	*	判断文件是否存在
	*/
	public static function Exists($path)
	{
		$path = ''.ROOT_PACK.'/'.$path.'';
		return file_exists($path);
	}
	
	/**
	*	获取扩展名
	*/
	public static function getExt($path)
	{
		$arr = explode('.', $path);
		$len = count($arr);
		return strtolower($arr[$len-1]);
	}
	
	/**
	*	获取完整路径
	*/
	public static function getAllpath($filepath)
	{
		$allpath= ROOT_PATH.'/'.$filepath;
		if(!file_exists($allpath))$allpath = $filepath;
		return $allpath;
	}
}